package cn.ljy.authority.utils;

import lombok.Data;

@Data
public class ResponseDTO<T> {
    private Integer code;
    private String message;
    private T data;
    private Long timestamp;

    public ResponseDTO() {
        this.timestamp = System.currentTimeMillis();
    }

    public static <T> ResponseDTO<T> success(T data) {
        ResponseDTO<T> response = new ResponseDTO<>();
        response.code = 200;
        response.message = "success";
        response.data = data;
        return response;
    }

    public static <T> ResponseDTO<T> success() {
        return success(null);
    }

    public static <T> ResponseDTO<T> error(Integer code, String message) {
        ResponseDTO<T> response = new ResponseDTO<>();
        response.code = code;
        response.message = message;
        return response;
    }

    public static <T> ResponseDTO<T> error(String message) {
        return error(500, message);
    }
}